using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;
using System.IO;

public partial class Admin_AddEmailTemplate : System.Web.UI.Page
{
    #region Viarible
    protected int Id
    {
        get
        {
            object o = ViewState["Id"];
            if (o != null)
                return (int)o;
            return int.MinValue;
        }
        set
        {
            ViewState["Id"] = value;
        }
    }
    static string prevPage = String.Empty;
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        if (Request.UrlReferrer != null)
            prevPage = Request.UrlReferrer.ToString();
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            this.Id = int.Parse(Request.QueryString["id"]);


        }
        LoadCurent();
        LoadData();
    }
    #region LoadCurent
    private void LoadCurent()
    {
        HtmlGenericControl ulEmail = (HtmlGenericControl)Master.FindControl("ulEmail");
        ulEmail.Attributes.Add("class", "current");
        HtmlGenericControl liSubAddEmail = (HtmlGenericControl)Master.FindControl("liSubAddEmail");
        liSubAddEmail.Attributes.Add("class", "sub_show");
        HtmlControl divSelectSubEmail = (HtmlControl)Master.FindControl("divSelectSubEmail");
        divSelectSubEmail.Attributes.Add("class", "select_sub show");
    }
    #endregion
    #region VoidSave and Reset
    protected void btnsave_Click(object sender, EventArgs e)
    {

        ADESSA.Entities.Newsletter _Newsletter = new ADESSA.Entities.Newsletter();
        if (this.Id != int.MinValue && this.Id != 0)
        {
            _Newsletter = NewsletterService.GetNewsletter(this.Id);
            if (_Newsletter != null)
                _Newsletter.UpdatedDate = DateTime.Now;
        }
        else
        {
            _Newsletter.CreatedDate = DateTime.Now;
            _Newsletter.Order = RTISettings.DefaultOrder;
        }
        _Newsletter.Title = txtTitle.Value.Trim();
        _Newsletter.Content = fck_Desc.Value.Trim();
        if (this.Id != int.MinValue && this.Id != 0)
        {
            NewsletterService.UpdateNewsletter(_Newsletter);
            Response.Redirect("EmailTemplate.aspx");
        }
        else
        {
            NewsletterService.CreateNewsletter(_Newsletter);
            Response.Redirect("EmailTemplate.aspx");
        }

    }
  
    protected void btnexit_Click(object sender, EventArgs e)
    {
        Response.Redirect(prevPage);
    }
    #endregion
    #region LoadData
    private void LoadData()
    {
        ADESSA.Entities.Newsletter _Newsletter = new ADESSA.Entities.Newsletter();
         if (this.Id != int.MinValue && this.Id != 0)
         {
             _Newsletter = NewsletterService.GetNewsletter(this.Id);
             if (_Newsletter != null)
             {
                 txtTitle.Value = _Newsletter.Title;
                 fck_Desc.Value = _Newsletter.Content;
             }
         }
    }
    
    #endregion
}
